package org.dromara.web.plugins.file;


import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class PDFFileResolver implements FileResolver{

    @Override
    public String resolve(String path) {
        try {
            PDDocument document = PDDocument.load(new File(path));
            PDFTextStripper pdfStripper = new PDFTextStripper();
            String text = pdfStripper.getText(document);
            return text;
        }catch (Exception e) {
            return "";
        }
    }

    @Override
    public String[] supportedExtensions() {
        return new String[]{"pdf"};
    }
}
